package com.eclipse.org.snms.serializer.actions;

import java.io.IOException;
import java.text.ParseException;

import com.eclipse.org.snms.reminder.ReminderObserver;
import com.eclipse.org.snms.reminder.ReminderSubject;
import com.eclipse.org.snms.reminder.ReminderSubjectConcrete;
import com.eclipse.org.snms.serializer.loadStickyNotes.SerializerConcreteSubject;
import com.eclipse.org.snms.serializer.storageAccess.*;
import com.eclipse.org.snms.serializer.updateStickyNote.ConcreteObserver;
import com.eclipse.org.snms.summary.SummaryObserver;
import com.eclipse.org.snms.summary.SummarySubjectConcrete;
/**
 * 
 * @author david
 *
 */
public class StartUp implements org.eclipse.ui.IStartup{

	
	public void earlyStartup() {
		ReminderSubjectConcrete rsc=new ReminderSubjectConcrete();
		rsc.subscribe(new ConcreteObserver());
				
		StorageAccess storageAccess = StorageAccess.getUniqueInstance();
		try {
			System.out.println("read?");
			storageAccess.readXML();
			// instantiate summary and serializer objects
			SummarySubjectConcrete summary = new SummarySubjectConcrete();
			SerializerConcreteSubject serializer = new SerializerConcreteSubject();
			
			// instantiate reminder object
			ReminderSubjectConcrete reminder = new ReminderSubjectConcrete(summary, serializer);
			//Ourcodes 	
			serializer.notifyObservers();
			// check sticky note deadlines
			while (true)
			{
				// if deadline expired 
				reminder.checkDeadlines();
				
				try
				{
					// sleep 60 seconds
					Thread.sleep(60000);
				}
				catch(InterruptedException e)
				{
					// print stack trace
					e.printStackTrace();
				}
				
				//reminder.printOutlist();
				System.out.println("------------------------------");
			}
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}
}
